<?php
/**
 * Created by JetBrains PhpStorm.
 * User: duonglt
 * Date: 10/14/13
 * Time: 10:23 AM
 * To change this template use File | Settings | File Templates.
 */

namespace Core;

use Exception;
use Zend\Config\Reader\Xml;


class Config{

    private static $_systemConf;
    private static $_danhmucConf;

    public static function getSystemConfig () {

        try{
            if(!self::$_systemConf){
                $reader = new Xml();
                $data = $reader->fromFile(CORE_CONFIGURATION_DIRECTORY.'\system.xml');
                self::$_systemConf = new \Zend\Config\Config($data);
            }

            return self::$_systemConf;
        }catch (Exception $e){

            \Logger::emergency("Kiểm tra file system.xml tại " . CORE_CONFIGURATION_DIRECTORY);
            die('Kiểm tra file system.xml');
        }

    }

    public static function getDanhMucConfig () {

        try{
            if(!self::$_danhmucConf){
                $reader = new Xml();
                $data = $reader->fromFile(CORE_CONFIGURATION_DIRECTORY.'\danhmuc.xml');
                self::$_danhmucConf = new \Zend\Config\Config($data);
            }

            return self::$_danhmucConf;
        }catch (Exception $e){

            \Logger::emergency("Kiểm tra file danhmuc.xml tại " . CORE_CONFIGURATION_DIRECTORY);
            die('Kiểm tra file danhmuc.xml');
        }

    }

    public static function getAdminSessionNameSpace()
    {
        return  'admin_'.self::getSystemConfig()->general->session_name_space;
    }

    public static function getApplicationSessionNameSpace()
    {
        return  'application_'.self::getSystemConfig()->general->session_name_space;
    }

    public static function getSessionNameSpace()
    {
        return  self::getSystemConfig()->general->session_name_space;
    }

    public static function getFrontModule()
    {
        return  self::getSystemConfig()->general->frontmodule;
    }

    public static function getAdminModule()
    {
        return  'admin';
    }

    public static function getAllUrlParam(){
        $resultArr = array();
        $danhmucConf = self::getDanhMucConfig();
        $urlParamConf = $danhmucConf->url_param;
        foreach ($urlParamConf as $key => $valArr) {
            $resultArr[$key] = $valArr->display_name.'('.$valArr->description.')';
        }

        return $resultArr;
    }

    public static function getInitialBalance()
    {
        $conf = self::getDanhMucConfig();
        return $conf->initial_balance;
    }

    public static  function getAllMenuTarget(){
        $resultArr = array();
        $dmConf = self::getDanhMucConfig();
        $conf = $dmConf->menu_url_target;
        foreach ($conf as $key => $val) {
            $resultArr[$key] = $val;
        }
        return $resultArr;
    }

    public static function getDefaultLanguage(){
        $config = self::getSystemConfig();
        return $config->general->language;
    }


    public static  function getCurrencyUnit(){
        $resultArr = array();
        $dmConf = self::getDanhMucConfig();
        $conf = $dmConf->currency_unit;
        foreach ($conf as $key => $val) {
            $resultArr[$key] = $val;
        }
        return $resultArr;
    }

    public static function getLangCodes(){
        $resultArr = array();
        $dmConf = self::getDanhMucConfig();
        $conf = $dmConf->lang_code;
        foreach ($conf as $key => $val) {
             $resultArr[$key] = $val;
        }
        return $resultArr;
    }

    public static function getDishProperties($lang){

        $resultArr = array();
        $dmConf = self::getDanhMucConfig();
        $conf = $dmConf->dish_property->$lang;
        foreach ($conf as $key => $val) {
            array_push($resultArr, array('key'=>$key, 'image'=>$val->image, 'name'=>$val->name));
        }
        return $resultArr;

    }

    public static function getDayInWeek($lang){
        $resultArr = array();
        $dmConf = self::getDanhMucConfig()->day->$lang;
        foreach ($dmConf as $key => $val) {
            $resultArr[$key] = $val;
        }
        return $resultArr;

    }
}